package cn.yuanqiao.web.controller.archive.danganzhengli;

import cn.yuanqiao.archive.danganzhengli.domain.FileAssociation;
import cn.yuanqiao.archive.danganzhengli.service.IFileAssociationService;

import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 互见号Controller
 *
 * @author xy
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/archive/association")
public class FileAssociationController extends BaseController
{
    @Autowired
    private IFileAssociationService fileAssociationService;

    /**
     * 查询互见号列表
     */
//    @RequiresPermissions("archive:association:list")
    @Log(title = "互见号", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(FileAssociation fileAssociation)
    {
        startPage();
        List<FileAssociation> list = fileAssociationService.selectFileAssociationList(fileAssociation);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('archive:hjh:button')")
    @GetMapping("/daList")
    public TableDataInfo daList(String dh)
    {
        startPage();
        List<Map<String,Object>> list = fileAssociationService.selectDaList(dh);
        return getDataTable(list);
    }

    /**
     * 导出互见号列表
     */
//    @RequiresPermissions("archive:association:export")
    @Log(title = "互见号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileAssociation fileAssociation)
    {
        List<FileAssociation> list = fileAssociationService.selectFileAssociationList(fileAssociation);
        ExcelUtil<FileAssociation> util = new ExcelUtil<FileAssociation>(FileAssociation.class);
        util.exportExcel(response, list, "互见号数据");
    }

    /**
     * 获取互见号详细信息
     */
//    @RequiresPermissions("archive:association:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fileAssociationService.selectFileAssociationById(id));
    }

    /**
     * 新增互见号
     */
//    @RequiresPermissions("archive:association:add")
    @Log(title = "互见号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileAssociation fileAssociation)
    {
        return toAjax(fileAssociationService.insertFileAssociation(fileAssociation));
    }

    /**
     * 修改互见号
     */
//    @RequiresPermissions("archive:association:edit")
    @Log(title = "互见号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileAssociation fileAssociation)
    {
        return toAjax(fileAssociationService.updateFileAssociation(fileAssociation));
    }

    /**
     * 删除互见号
     */
//    @RequiresPermissions("archive:association:remove")
    @Log(title = "互见号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fileAssociationService.deleteFileAssociationByIds(ids));
    }
    //判断是否有该档案权限
    @GetMapping("/getRole/{menuId}/{categoryId}")
    public AjaxResult getRole(@PathVariable("menuId")Long menuId,@PathVariable("categoryId")Long  categoryId){

        return AjaxResult.success(fileAssociationService.getRole(menuId,categoryId));

    }
    //查看该档案是否有按钮
    @GetMapping("/getButton/{daId}")
    public AjaxResult getButton(@PathVariable("daId")Long daId){

        return AjaxResult.success(fileAssociationService.getButton(daId));

    }
    //判断档案是否可以看原文
    @GetMapping("/getDocRole/{daId}/{menuId}")
    public AjaxResult getDocRole(@PathVariable("daId")Long daId,@PathVariable("menuId")Long menuId){

        return AjaxResult.success(fileAssociationService.getDocRole(daId,menuId));

    }

}
